home *** CD-ROM | disk | FTP | other *** search
Text File | 1985-10-15 | 3.5 KB | 103 lines | [TEXT/MACA] |
- \ Requires
- \ A few utility words by Jay Scott, June 1985.
- \
- \ Original Neon™ code © Copyright 1985 Jay Scott
- \ Released October 1985 by Tom O'Brien
- \ For free public distribution (not to be sold)
- \ provided this notice is kept intact.
- \
-
- \ In a source file "Source File" put:
- \
- \ Requires "This File" \ if the source file needs thisFile loaded first
- \ Requires "That File" \ if the source file needs thatFile loaded first
- \ Marker "Source File" \ declare that "Source File" is loaded
- \
- \ "This File" (and all other required files) should start with the line
- \
- \ Marker "This File"
- \
- \ so that Requires can tell whether it has already been loaded. Requires will
- \ load each file only if it can't find in the dictionary a marker with the
- \ same name as the file to be loaded.
- \
- \ If you reload a file with a marker, Marker will automatically forget
- \ the old one. You can't have two copies of one file loaded at once.
- \
- \ "This File" and "That File" can require other files.
- \ Nesting can't go deeper than six files altogether, counting both
- \ // and Requires.
- \
- \ To explicitly forget a marker, use Forget" .
-
-
- \ Expects a search string at HERE & searches all the right vocabularies
- \ for it. The search string can contain blanks and other obnoxious characters.
- \ This code is lifted from FIND in the nucleus.
- : findHere ( -- false ) \ if not found
- ( -- pfa lenbyte true ) \ if found
- ufind dup 0= if \ what's UFIND? it always leaves 0...
- drop
- here context @ (find) \ look in context vocab
- dup 0= if \ if not there,
- context current - if \ and if current <> context,
- drop here latest (find) \ look in current vocab
- then
- then
- then
- ;
-
-
- : Requires ( -- ; "fileName" )
- new: loadFile \ new file on the file stack
- ascii " word \ read quoted string from input stream
- here count name: topFile
- findHere if \ file is already loaded, do nothing
- 2drop
- else \ file isn't loaded, announce & load it
- cr ." Requires " here count type
- interpret: loadFile
- then
- remove: loadFile \ remove the file from the file stack
- ;
-
-
- \ Forgets a word, given its PFA.
- \ This code is lifted from the original forget.
- : (Forget) ( pfa -- )
- dup fence u< abort" can't forget in protected dictionary"
- dup nfa -> dp
- lfa @ current !
- ;
-
-
- \ For forgetting words with spaces in their names, like markers for instance.
- : Forget" ( -- ; "Name" )
- definitions
- ascii " word
- findHere 0= abort" I can't find that word."
- drop (Forget)
- ;
-
-
- \ Creates words that may have embedded spaces in their names.
- \ It’s to be used to create words with the same names as their files.
- \ Also automatically forgets back if there's a word with the same name.
- : Marker { \ oldHere -- ; "Name" }
- definitions
- ascii " word \ read "Name" from the input stream
- findHere if \ if word already exists,
- here -> oldHere
- cr ." forgetting old version of " here count type
- drop (Forget) \ forget it
- oldHere c@ here c! \ make the old name's length correct
- then
- here 1 and if \ ensure even word boundary
- 0 c,
- then
- $ 80 s, \ allot the name field
- latest , \ make a link field
- current ! \ make it the start of the dictionary
- ' null cfa , \ make a CFA to do nothing
- ;
-